import logging
from logging import handlers

logOut = logging.getLogger("mylog")
logOut.setLevel(level=logging.DEBUG)

# 获取文件日志句柄并设置日志级别，第二层过滤
handler = logging.FileHandler("log.txt", encoding='utf-8')
handler.setLevel(logging.INFO)

# 生成并设置文件日志格式，其中name为上面设置的mylog
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)

# 获取流句柄并设置日志级别，第二层过滤
console = logging.StreamHandler()
console.setLevel(logging.WARNING)

# 为logger对象添加句柄
logOut.addHandler(handler)
logOut.addHandler(console)


def logInfo(msg):
    logOut.info(msg)


def logDebug(msg):
    logOut.debug(msg)


def logWarning(msg):
    logOut.warning(msg)

